<%@ Page Language="C#" Inherits="Castle.MonoRail.Views.AspView.ViewAtDesignTime<IPostsView>" %>
<%@ Import namespace="KenEgozi.Com.Domain.Aggregates.Post"%>
<%@ Import namespace="KenEgozi.Com.Weblog.Interfaces"%>
<component:CaptureFor id="AdditionalScriptTag" append="after">
	<script type="text/javascript" src="~/assets/scripts/prototype-1.6.0.2.js"></script>
	<script type="text/javascript">
	function showComments(postId) {
		var commentsContainer = $('post_' + postId + '_comments').down('td');
		if (commentsContainer.innerHTML.length > 5)
			commentsContainer.update(' ');
		else {
			new Ajax.Updater(commentsContainer, '~/admin/comments/new.aspx', {
				parameters: {postId: postId, isAsync:true }
			});
		}
	}

	function deleteComment(commentId) {
		if (confirm('Are you sure?'))
			new Ajax.Request('~/admin/comments/delete.aspx', {
				parameters: {id: commentId},
				onComplete: function (r) { alert(r.responseText); }
			});
	}

	function approveComment(commentId) {
		new Ajax.Request('~/admin/comments/approve.aspx', {
			parameters: {id: commentId},
			onComplete: function (r) { alert(r.responseText); }
		});
	}
	</script>
</component:CaptureFor>

<table class="posts-with-new-comments">
	<tr>
		<th>Id</th>
		<th>Title</th>
		<th>Action</th>
	</tr>
<% foreach (Post post in view.Posts) { %>
<tr id="post_<%=post.Id %>" class="post-details">
	<td><%=post.Id %></td>
	<td><a target="_blank" href="~/<%=post.Permalink %>"><%=post.Title %></a></td>
	<td><button onclick="showComments(<%=post.Id %>);">Comments</button></td>
</tr>
<tr id="post_<%=post.Id %>_comments" class="post-new-comments">
	<td colspan="3"></td>
</tr>
<% } %>
</table>
